package main

import (
	"fmt"
	"sync"
	"time"
)

var op int = 0

func main() {
	var once sync.Once
	onceBody := func() {
		op = op + 1
		fmt.Println("Only once")
	}
	//当多个goroutine只初始化一次变量,这时候sync.Once能够派上用场.
	for i := 0; i < 10; i++ {
		go func() {
			once.Do(onceBody)
		}()
	}
	fmt.Println("op result :", op)
	fmt.Printf("3e6 result:%v\n:", 3e9)
	time.Sleep(3e9)
}
